package cn.hello1023.springbootlabs;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class Demo {
    @RequestMapping("/hello1")
    public String hello1(){
        return "Hello World";
    }

    @RequestMapping("/hello2")
    public Result<String> hello2(){
        Result<String> result = new Result<String>();
        result.setCode(200);
        result.setMsg("操作成功");
        result.setData("Hello World");
        return result;
    }

    @RequestMapping("/hello3")
    public Result<User> hello3(){
        Result<User> result = new Result<>();
        User user = new User();
        user.setName("Zhang");
        user.setAge(20);

        result.setCode(200);
        result.setMsg("操作成功");
        result.setData(user);
        return result;
    }

    @RequestMapping("/hello4")
    public Result<List<User>> hello4(){
        Result<List<User>> result = new Result<>();
        List users = new ArrayList();

        User user = new User();
        user.setName("Zhang");
        user.setAge(20);
        users.add(user);

        User user2 = new User();
        user2.setName("Wang");
        user2.setAge(20);
        users.add(user2);

        result.setCode(200);
        result.setMsg("操作成功");
        result.setData(users);
        return result;
    }
}
